package br.inf.solutions.apresentacoes.ssp.control.validator;

import java.util.Date;
import java.util.Map;

import br.com.vexillum.control.validator.Validator;
import br.com.vexillum.util.Return;
import br.inf.solutions.apresentacoes.ssp.model.StealthWeapon;

public class StealthWeaponValidator extends Validator {

	public StealthWeaponValidator(Map<String, Object> mapData) {
		super(mapData);
	}
	
	@Override
	public Return validateSave() {
		Return ret = super.validateSave();
		if(ret.isValid()){
			ret.concat(validadeReturnDate());
		}
		return ret;
	}

	private Return validadeReturnDate(){
		Return ret = new Return(true);
		StealthWeapon stealthWeapon = (StealthWeapon) entity;
		Date startDate = stealthWeapon.getStartDate();
		Date finalDate = stealthWeapon.getReturnDate();
		if(finalDate != null){
			if(finalDate.before(startDate)){
				ret.concat(creatReturn("returnDate", getValidationMessage(null, "validadereturndate", false)));
			}
		}
		return ret;
	}
	
}
